﻿@model Nop.Web.Models.Catalog.StoreReviewOverviewModel
@using Nop.Core.Domain.Catalog;

@{
    //Rating CSS Classes
    int totalreviews = Model.TotalReviews;
    float ratingsum = 0;
    if (totalreviews != 0) {
        ratingsum = (float)Model.RatingSum / totalreviews;
    }
    float maxrating = Rating.MaxRating;
    float rating = (float)(ratingsum / maxrating) * 5;
    var ratingBase = Math.Floor(rating);
    var ratingTop = (rating - ratingBase) * 10;
    int ratingTopRound = Convert.ToInt32(ratingTop);
    var starFirst = 0;
    var starSecond = 0;
    var starThird = 0;
    var starFourth = 0;
    var starFifth = 0;
    if (ratingBase >= 0)
    {
        if (ratingBase >= 1)
        {
            starFirst = 10;
            if (ratingBase >= 2)
            {
                starSecond = 10;
                if (ratingBase >= 3)
                {
                    starThird = 10;
                    if (ratingBase >= 4)
                    {
                        starFourth = 10;
                        if (ratingBase >= 5)
                        {
                            starFifth = 10;
                        }
                        else
                        {
                            starFifth = ratingTopRound;
                        }
                    }
                    else
                    {
                        starFourth = ratingTopRound;
                    }
                }
                else
                {
                    starThird = ratingTopRound;
                }
            }
            else
            {
                starSecond = ratingTopRound;
            }
        }
        else
        {
            starFirst = ratingTopRound;
        }
    }
    else { }
    }

    
    <div class="product-rating" title="@Math.Round(ratingsum, 1, MidpointRounding.AwayFromZero)">
        @if (Model.TotalReviews > 0) { 
        <div class="rating-stars">
            <div class="star-base"><div class="star-top rate-@starFirst"></div></div>
            <div class="star-base"><div class="star-top rate-@starSecond"></div></div>
            <div class="star-base"><div class="star-top rate-@starThird"></div></div>
            <div class="star-base"><div class="star-top rate-@starFourth"></div></div>
            <div class="star-base"><div class="star-top rate-@starFifth"></div></div>
            <span>(@Model.TotalReviews ratings)</span>
        </div>
        
        }
    </div>



